<?php

namespace app\common\model;

use think\Model;

class Admin extends Model
{
    public function login($data)
    {
        $validate = new \app\common\validate\Admin();
        if (!$validate->check($data)) {
            return $validate->getError();
        }
        unset($data['verify']);

        $status = $this->where($data)->find();
        if ($status) {
            session('username', $data['username']);
            return 1;
        }else {
            return '用户名或者密码不正确！';
        }
    }

    public function edit($data)
    {
        $validate = new \app\common\validate\Admin();
        if (!$validate->scene('edit')->check($data)) {
            return $validate->getError();
        }
        $result = $this->isUpdate(true)->save($data);
        if ($result) {
            session('username', $data['username']);
            return 1;
        }else {
            return '信息没有任何修改！';
        }
    }
}
